﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script>
    var currRowId = 1;
    var currStatus = '@ViewBag.status';
    $(function () {
        initControl();
        gridList();
    });
    function initControl() {
        $('select').bindSelect();
        $("input[type='radio'][value=" + currStatus + "].category").prop("checked", true);
        $('.category').on("click", function () {
            var status = $("input[type='radio'].category:checked").val();
            if (currStatus != status) {
                window.location.href = '/BOM/Manufacture/StampingProcessList?status=' + status;
            }
        })
    }
    function gridList() {
        var status = $("input[type='radio'].category:checked").val();
        if (status == 0) {
            gridList1();
        } else {
            gridList2();
        }
    }
    function gridList1() {
        $("#grid111").show();
        $("#grid222").hide();
        $('#btn_add').removeClass("disabled");
        $('#btn_remove').removeClass("disabled");
        var $gridList = $("#gridList1");
        $gridList.dataGrid({
            url: "/BOM/Manufacture/GetStampingProcessListJson",
            postData: $("#form1").formSerialize(),
            height: $(window).height() - 124,
            colModel: [
                //{
                //    label: '<a id="grid_chb_selectAll" onclick="grid_chb_selectAll()">全选</a>', name: 'ProcessID', width: 40, align: 'center', sortable: false, frozen: true, formatter: function (cellvalue, options, rowObject) {
                //        return '<input class="grid_chb_select" value="' + cellvalue + '" name="checkbox" type="checkbox" onclick="" style="vertical-align:middle">';
                //    }
                //},
                { label: '零件编号', name: 'FProductionNO', width: 120, align: 'left', sortable: false, frozen: true },
                { label: '零件名称', name: 'FProductionName', width: 200, align: 'left', sortable: false, frozen: true },
                { label: '工序号', name: 'ProcessNO', width: 50, align: 'left', sortable: false, frozen: true },
                { label: '工序名称', name: 'ProcessName', width: 90, align: 'left', sortable: false, frozen: true },
                { label: '主生产线', name: 'ZLineName', width: 70, align: 'left', sortable: false },
                { label: '主线设备型号', name: 'EquipNO', width: 100, align: 'left', sortable: false },
                { label: '设备编号', name: 'EquipSBNO', width: 100, align: 'left', sortable: false },
                { label: '单件生产工时', name: 'Manhour', width: 90, align: 'right', sortable: false },
                { label: '单件工艺工时', name: 'Technologyhour', width: 90, align: 'right', sortable: false },
                { label: '批次准结工时', name: 'Moduelhour', width: 90, align: 'right', sortable: false },
                { label: '批次工艺准结工时', name: 'PModuelhour', width: 120, align: 'right', sortable: false },
                { label: '工艺定员', name: 'PerNum', width: 60, align: 'right', sortable: false },
                { label: '副生产线1', name: 'FLineName1', width: 70, align: 'left', sortable: false },
                { label: '副线1设备型号', name: 'EquipNO1', width: 100, align: 'left', sortable: false },
                { label: '副线1设备编号', name: 'EquipSBNO1', width: 100, align: 'left', sortable: false },
                { label: '单线生产工时', name: 'Manhour1', width: 90, align: 'right', sortable: false },
                { label: '单件工艺工时', name: 'Technologyhour1', width: 90, align: 'right', sortable: false },
                { label: '批次准结工时', name: 'Moduelhour1', width: 90, align: 'right', sortable: false },
                { label: '批次工艺准结工时', name: 'PModuelhour1', width: 120, align: 'right', sortable: false },
                { label: '工艺定员', name: 'PerNum1', width: 60, align: 'right', sortable: false },
                { label: '副生产线2', name: 'FLineName2', width: 70, align: 'left', sortable: false },
                { label: '副线2设备型号', name: 'EquipNO2', width: 100, align: 'left', sortable: false },
                { label: '副线2设备编号', name: 'EquipSBNO2', width: 100, align: 'left', sortable: false },
                { label: '单件生产工时', name: 'Manhour2', width: 90, align: 'right', sortable: false },
                { label: '单件工艺工时', name: 'Technologyhour2', width: 90, align: 'right', sortable: false },
                { label: '批次准结工时', name: 'Moduelhour2', width: 90, align: 'right', sortable: false },
                { label: '批次工艺准结工时', name: 'PModuelhour2', width: 120, align: 'right', sortable: false },
                { label: '工艺定员', name: 'PerNum2', width: 60, align: 'right', sortable: false },
                { label: '创建人员', name: 'FCreateBy', width: 80, align: 'left', sortable: false },
                { label: '创建日期', name: 'FCreateDate', width: 70, align: 'center', sortable: false },
                { label: '创建时间', name: 'FCreateTime', width: 70, align: 'center', sortable: false },
                { label: '修改人员', name: 'FUpdateBy', width: 80, align: 'left', sortable: false },
                { label: '修改日期', name: 'FUpdateDate', width: 70, align: 'center', sortable: false },
                { label: '修改时间', name: 'FUpdateTime', width: 70, align: 'center', sortable: false },
                { label: '', name: 'FProCompanyNO', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FProCompanyName', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FProCompanyAll', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FWorkshop', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FWorkshopName', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FWorkshopAll', width: 80, align: 'center', hidden: true },
                { label: '', name: 'Manhour_JQ', width: 80, align: 'center', hidden: true },
                { label: '', name: 'Technologyhour_JQ', width: 80, align: 'center', hidden: true },
                { label: '', name: 'Moduelhour_JQ', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FContainerNO', width: 80, align: 'center', hidden: true },
                { label: '', name: 'MoldNO', width: 80, align: 'center', hidden: true },
                { label: '', name: 'ProcessID', width: 80, align: 'center', hidden: true },
                { label: '主生产线', name: 'ZLineNO', width: 70, align: 'left', hidden: true },
                { label: '副生产线1', name: 'FLineNO1', width: 70, align: 'left', hidden: true },
                { label: '副生产线2', name: 'FLineNO2', width: 70, align: 'left', hidden: true },
            ],
            pager: "#gridPager1",
            sortname: 'FProductionNO asc, ZLineNO desc, ProcessNO asc',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {

            },
            loadComplete: function () {
                //hackHeight("#gridList");
                $gridList.jqGrid('setSelection', currRowId);
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
            },
            onPaging: function (page_btn) {
                currRowId = 1;
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            reloadGrid1();
        });
    }
    function gridList2() {
        $("#grid111").hide();
        $("#grid222").show();
        var $gridList = $("#gridList2");
        $gridList.dataGrid({
            url: "/BOM/Manufacture/GetStampingProcessDocumentJson",
            postData: $("#form1").formSerialize(),
            height: $(window).height() - 124,
            colModel: [
                {
                    label: '更改方式', name: 'ChangeType', width: 60, align: 'center', sortable: false, frozen: true, formatter: function (cellvalue) {
                        return cellvalue == "XZ" ? "新增" : cellvalue == "XG" ? "修改" : cellvalue == "SC" ? "删除" : "";
                    }
                },
                { label: '零件编号', name: 'FProductionNO', width: 120, align: 'left', sortable: false, frozen: true },
                { label: '零件名称', name: 'FProductionName', width: 200, align: 'left', sortable: false, frozen: true },
                { label: '工序号', name: 'ProcessNO', width: 50, align: 'left', sortable: false, frozen: true },
                { label: '工序名称', name: 'ProcessName', width: 90, align: 'left', sortable: false },
                { label: '主生产线', name: 'ZLineNO', width: 70, align: 'left', sortable: false },
                { label: '主线设备型号', name: 'EquipNO', width: 100, align: 'left', sortable: false },
                { label: '设备编号', name: 'EquipSBNO', width: 100, align: 'left', sortable: false },
                { label: '单件生产工时', name: 'Manhour', width: 90, align: 'right', sortable: false },
                { label: '单件工艺工时', name: 'Technologyhour', width: 90, align: 'right', sortable: false },
                { label: '批次准结工时', name: 'Moduelhour', width: 90, align: 'right', sortable: false },
                { label: '批次工艺准结工时', name: 'PModuelhour', width: 120, align: 'right', sortable: false },
                { label: '工艺定员', name: 'PerNum', width: 60, align: 'right', sortable: false },
                { label: '副生产线1', name: 'FLineNO1', width: 70, align: 'left', sortable: false },
                { label: '副线1设备型号', name: 'EquipNO1', width: 100, align: 'left', sortable: false },
                { label: '副线1设备编号', name: 'EquipSBNO1', width: 100, align: 'left', sortable: false },
                { label: '单线生产工时', name: 'Manhour1', width: 90, align: 'right', sortable: false },
                { label: '单件工艺工时', name: 'Technologyhour1', width: 90, align: 'right', sortable: false },
                { label: '批次准结工时', name: 'Moduelhour1', width: 90, align: 'right', sortable: false },
                { label: '批次工艺准结工时', name: 'PModuelhour1', width: 120, align: 'right', sortable: false },
                { label: '工艺定员', name: 'PerNum1', width: 60, align: 'right', sortable: false },
                { label: '副生产线2', name: 'FLineNO2', width: 70, align: 'left', sortable: false },
                { label: '副线2设备型号', name: 'EquipNO2', width: 100, align: 'left', sortable: false },
                { label: '副线2设备编号', name: 'EquipSBNO2', width: 100, align: 'left', sortable: false },
                { label: '单件生产工时', name: 'Manhour2', width: 90, align: 'right', sortable: false },
                { label: '单件工艺工时', name: 'Technologyhour2', width: 90, align: 'right', sortable: false },
                { label: '批次准结工时', name: 'Moduelhour2', width: 90, align: 'right', sortable: false },
                { label: '批次工艺准结工时', name: 'PModuelhour2', width: 120, align: 'right', sortable: false },
                { label: '工艺定员', name: 'PerNum2', width: 60, align: 'right', sortable: false },
                { label: '创建人员', name: 'FCreateBy', width: 80, align: 'left', sortable: false },
                { label: '创建日期', name: 'FCreateDate', width: 70, align: 'center', sortable: false },
                { label: '创建时间', name: 'FCreateTime', width: 70, align: 'center', sortable: false },
                { label: '修改人员', name: 'FUpdateBy', width: 80, align: 'left', sortable: false },
                { label: '修改日期', name: 'FUpdateDate', width: 70, align: 'center', sortable: false },
                { label: '修改时间', name: 'FUpdateTime', width: 70, align: 'center', sortable: false },
                { label: '', name: 'FProCompanyNO', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FProCompanyName', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FProCompanyAll', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FWorkshop', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FWorkshopName', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FWorkshopAll', width: 80, align: 'center', hidden: true },
                { label: '', name: 'Manhour_JQ', width: 80, align: 'center', hidden: true },
                { label: '', name: 'Technologyhour_JQ', width: 80, align: 'center', hidden: true },
                { label: '', name: 'Moduelhour_JQ', width: 80, align: 'center', hidden: true },
                { label: '', name: 'FContainerNO', width: 80, align: 'center', hidden: true },
                { label: '', name: 'MoldNO', width: 80, align: 'center', hidden: true },
                { label: '', name: 'ProcessID', width: 80, align: 'center', hidden: true }
            ],
            pager: "#gridPager2",
            sortname: 'FUpdateDate desc, FUpdateTime desc,FProductionNO asc, ZLineNO desc, ProcessNO asc',
            viewrecords: true,  //是否显示行数
            rownumWidth: 40,
            gridComplete: function () {

            },
            loadComplete: function () {
                //hackHeight("#gridList");
                $gridList.jqGrid('setSelection', currRowId);
            },
            onSelectRow: function (rowid) {
                currRowId = rowid;
            },
            onPaging: function (page_btn) {
                currRowId = 1;
            }
        });
        $gridList.jqGrid('setLabel', 0, '序号', 'rowNumberHeaderStyle');
        $gridList.jqGrid('setFrozenColumns');
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: $("#form1").formSerialize(),
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/BOM/Manufacture/StampingProcess"
        });
    }
    function btn_remove() {
        var $gridList = $("#gridList1");
        var rowData = $gridList.jqGrid('getRowData', currRowId);
        $.modalConfirm("注：您确定要【删除】当前冲压工序数据吗？", function (r) {
            if (r) {
                $.submitForm({
                    url: "/BOM/Manufacture/SubmitStampingProcess?status=D",
                    param: rowData,
                    success: function () {
                        reloadGrid1();
                    }
                })
            }
        });
    }
    function grid_chb_selectAll() {
        var txt = $('#grid_chb_selectAll').text();
        alert(txt);
        if (txt == "全选") {
            $('.grid_chb_select').prop("checked", true);
            $('#grid_chb_selectAll').text("反选");
        } else {
            $('.grid_chb_select').prop("checked", false);
            $('#grid_chb_selectAll').text("全选");
        }
    }
    function reloadGrid1() {
        $("#gridList1").jqGrid('setGridParam', {
            postData: $("#form1").formSerialize(),
        }).trigger('reloadGrid');
    }
    function btn_export() {
        var url = "/Common/ExcelExport?" + init_sql();
        location.href = url;
    }
    function init_sql() {
        var status = $("input[type='radio'].category:checked").val();
        if (status == 0) {
            return init_sql1();
        } else {
            return init_sql2();
        }
    }
    function init_sql1() {
        var tablename = "V_GYK_41_CY_TecGXData";
        var condition = "UseUnit='@FriendStar.Code.Configs.GetValue("UseUnit")'";
        var cols = [];
        //获取列字段
        var colModel = $("#gridList1").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel.replace(/<[^>]+>/g, "") + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#FProduction').val() != '') {
            condition += " AND (FProductionNO LIKE '%" + $('#FProduction').val() + "%' AND FProductionName LIKE '%" + $('#FProduction').val() + "%')";
        }
        if ($('#Process').val() != '') {
            condition += " AND (ProcessNO LIKE '%" + $('#Process').val() + "%' OR ProcessName LIKE '%" + $('#Process').val() + "%')";
        }
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY FProductionNO ASC, ZLineNO DESC, ProcessNO ASC";
        return "sql=" + sql;
    }
    function init_sql2() {
        var tablename = "V_GYK_43_CY_TecGXData_DA";
        var condition = "UseUnit='@FriendStar.Code.Configs.GetValue("UseUnit")'";
        var cols = [];
        //获取列字段
        var colModel = $("#gridList2").jqGrid('getGridParam', 'colModel');
        for (var i = 0; i < colModel.length; i++) {
            var columnHidden = colModel[i].hidden;
            var columnName = colModel[i].name;
            var columnLabel = colModel[i].label;
            if (columnHidden == false && columnName != "rn" && columnName != "") {
                if (columnLabel != '') {
                    cols.push(columnName + ' [' + columnLabel.replace(/<[^>]+>/g, "") + ']');
                } else {
                    cols.push(columnName);
                }
            }
        }
        if ($('#FProduction').val() != '') {
            condition += " AND (FProductionNO LIKE '%" + $('#FProduction').val() + "%' AND FProductionName LIKE '%" + $('#FProduction').val() + "%')";
        }
        if ($('#Process').val() != '') {
            condition += " AND (ProcessNO LIKE '%" + $('#Process').val() + "%' OR ProcessName LIKE '%" + $('#Process').val() + "%')";
        }
        var sql = "SELECT " + cols.join(',') + " FROM " + tablename + " WHERE " + condition + " ORDER BY FUpdateDate DESC, FUpdateTime DESC, FProductionNO ASC, ZLineNO DESC, ProcessNO ASC";
        return "sql=" + sql;
    }
</script>
<div id="layout" style="height: 100%; width: 100%;">
    <form id="form1">
        <div style="padding: 12px 0 5px 0; padding-left:15px; border-bottom:1px solid #ccc;" class="line-table input-width-140">
            <div class="btn-group" style="margin-right:20px;">
                <input id="radio11" class="category" name="category" type="radio" value="0" checked="checked" /><label for="radio11" class="suffix">明细</label><br />
                <input id="radio12" class="category" name="category" type="radio" value="1" /><label for="radio12" class="suffix">更改</label> &nbsp;&nbsp;&nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                零件<br /><input id="FProduction" name="FProduction" type="text" class="form-control" /> &nbsp;
            </div>
            <div class="btn-group" style="margin-top:-9px;">
                工序<br /><input id="Process" name="Process" type="text" class="form-control" /> &nbsp;
            </div>
            <div class="btn-group">
                <a id="btn_search" class="btn btn-primary center-block" onclick=""><span class="glyphicon glyphicon-search"></span> 检索</a>
            </div>
            <div class="btn-group" style="float:right;">
                <a id="btn_reload" class="btn btn-primary center-block" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span> 刷新</a>
                <a id="btn_add" class="btn btn-primary center-block disabled" onclick="btn_add()"><span class="glyphicon glyphicon-plus"></span> 输入</a>
                <a id="btn_remove" class="btn btn-primary center-block disabled" onclick="btn_remove()"><span class="glyphicon glyphicon-trash"></span> 删除</a>
                <a id="btn_export" class="btn btn-primary center-block" onclick="btn_export()"><span class="glyphicon glyphicon-download"></span> 导出</a>
            </div>
        </div>
    </form>
    <div id="grid111" style="">
        <table id="gridList1"></table>
        <div id="gridPager1"></div>
    </div>
    <div id="grid222" style="">
        <table id="gridList2"></table>
        <div id="gridPager2"></div>
    </div>
</div>

